﻿using System.Collections.Generic;
using System.Linq;

namespace SX.Core.Data
{
    /// <summary>
    /// 仓储
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public partial interface IRepository<T> where T : BaseEntity
    {
        /// <summary>
        /// 通过标识获取实体
        /// </summary>
        /// <param name="id">标识</param>
        /// <returns>实体</returns>
        T GetById(object id);

        /// <summary>
        /// 添加实体
        /// </summary>
        /// <param name="entity">实体</param>
        void Insert(T entity);

        /// <summary>
        /// 批量添加实体
        /// </summary>
        /// <param name="entities">实体列表</param>
        void Insert(IEnumerable<T> entities);

        /// <summary>
        /// 更新实体
        /// </summary>
        /// <param name="entity">实体</param>
        void Update(T entity);

        /// <summary>
        /// 批量更新实体
        /// </summary>
        /// <param name="entities">实体列表</param>
        void Update(IEnumerable<T> entities);

        /// <summary>
        /// 删除实体
        /// </summary>
        /// <param name="entity">实体</param>
        void Delete(T entity);

        /// <summary>
        /// 批量删除实体
        /// </summary>
        /// <param name="entities">实体列表</param>
        void Delete(IEnumerable<T> entities);

        /// <summary>
        /// 取得表数据
        /// </summary>
        IQueryable<T> Table { get; }

        /// <summary>
        /// 启用No tracking（EF特性）查询一个表的数据，只有你需要导入只读操作数据才用
        /// </summary>
        IQueryable<T> TableNoTracking { get; }
    }
}
